﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package net.wooga.pets.controllers.hiredoctor {
    import net.wooga.pets.loading.vos.*;
    import net.wooga.pets.events.*;
    import net.wooga.pets.constants.*;
    import org.robotlegs.mvcs.*;

    public class BuyADoctorCommand extends Command {

        public var event:InfoEvent;

        override public function execute():void{
            var _local1:RequestEvent = new RequestEvent(EventConstants.SEND_REQUEST, this.onResult);
            _local1.addRequest("buy_doctor", {id:this.event.id});
            dispatch(_local1);
        }
        private function onResult(_arg1:ResultVO):void{
            var _local2:Object;
            var _local3:Object;
            var _local4:int;
            if (_arg1.success){
                _local2 = _arg1.data.buy_doctor;
                _local3 = _local2.changes;
                _local4 = (_local3.coins_old - _local3.coins_new);
                this.track(_local4);
                this.closePopup();
                dispatch(new InfoEvent(EventConstants.UPDATE_USER_DATA, null, {changes:_local3}));
                dispatch(new InfoEvent(EventConstants.ADD_HIRED_DOCTOR, this.event.id, _local2.doctor));
            };
        }
        private function track(_arg1:int):void{
            var _local2:Object = {type:"buy_doctor", subtype1:_arg1};
            dispatch(new TrackingEvent(TrackingConst.TRACK, TrackingConst.EVENT, _local2));
        }
        private function closePopup():void{
            var _local1:InfoEvent = new InfoEvent(EventConstants.CLOSE_POPUP_BY_TYPE, ProtocolConstants.BUY_DOCTOR);
            dispatch(_local1);
        }

    }
}//package net.wooga.pets.controllers.hiredoctor 
